package bastanteo.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.JOptionPane;

import bastanteo.excepcion.DAOExcepcion;
import bastanteo.negocio.PoderNegocio;

/**
 * Servlet implementation class PoderInsertarServlet
 */
@WebServlet("/PoderInsertarServlet")
public class PoderInsertarServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public PoderInsertarServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		
		
		
		
		String x = request.getParameter("txtcodigo");
		String y = request.getParameter("txtnombre");
		String z = request.getParameter("tipo");
		
		
        
         if (x!= "" & y!= "") {
		
		
		PoderNegocio negocio = new PoderNegocio();
		
		try {
			negocio.insertarPoder(x, y,z);
			if(bastanteo.negocio.PoderNegocio.AS == 1) {
				RequestDispatcher rd = request.getRequestDispatcher("error5.jsp");
				rd.forward(request, response);
				bastanteo.negocio.PoderNegocio.AS = 0;
			}else {
				RequestDispatcher rd = request.getRequestDispatcher("agregarpoderes.jsp");
				rd.forward(request, response);
				
			}
				
			
			} catch (DAOExcepcion e) {
			RequestDispatcher rd = request.getRequestDispatcher("error5.jsp");
			rd.forward(request, response);
								 }
		 }
         
         
	}
		
	
	
}
